home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_xemacs.idb / usr / freeware / lib / xemacs-20.4 / lisp / w3 / url-misc.el.z / url-misc.el
Encoding:
Text File  |  1998-05-21  |  6.7 KB  |  193 lines

  1. ;;; url-misc.el --- Misc Uniform Resource Locator retrieval code
  2. ;; Author: wmperry
  3. ;; Created: 1997/12/26 23:04:07
  4. ;; Version: 1.23
  5. ;; Keywords: comm, data, processes
  6.  
  7. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  8. ;;; Copyright (c) 1993 - 1996 by William M. Perry <wmperry@cs.indiana.edu>
  9. ;;; Copyright (c) 1996, 1997 Free Software Foundation, Inc.
  10. ;;;
  11. ;;; This file is not part of GNU Emacs, but the same permissions apply.
  12. ;;;
  13. ;;; GNU Emacs is free software; you can redistribute it and/or modify
  14. ;;; it under the terms of the GNU General Public License as published by
  15. ;;; the Free Software Foundation; either version 2, or (at your option)
  16. ;;; any later version.
  17. ;;;
  18. ;;; GNU Emacs is distributed in the hope that it will be useful,
  19. ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21. ;;; GNU General Public License for more details.
  22. ;;;
  23. ;;; You should have received a copy of the GNU General Public License
  24. ;;; along with GNU Emacs; see the file COPYING.  If not, write to the
  25. ;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  26. ;;; Boston, MA 02111-1307, USA.
  27. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  28.  
  29. (require 'url-vars)
  30. (require 'url-parse)
  31. (require 'widget)
  32. (autoload 'Info-goto-node "info" "" t)
  33.  
  34. (defun url-netrek (url)
  35.   ;; Start a netrek client
  36.   (if (get-buffer url-working-buffer)
  37.       (kill-buffer url-working-buffer))
  38.   (let ((data (url-generic-parse-url url)))
  39.     (error
  40.      "I should launch netrek on: %s %s" (url-host data) (url-port data))))
  41.  
  42. (defun url-info (url)
  43.   ;; Fetch an info node
  44.   (if (get-buffer url-working-buffer)
  45.       (kill-buffer url-working-buffer))
  46.   (let* ((data (url-generic-parse-url url))
  47.      (fname (url-filename data))
  48.      (node (url-unhex-string (or (url-target data) "Top"))))
  49.     (if (and fname node)
  50.     (Info-goto-node (concat "(" fname ")" node))
  51.       (error "Malformed url: %s" url))))
  52.  
  53. (defun url-finger (url)
  54.   ;; Find a finger reference
  55.   (setq url-current-mime-headers '(("content-type" . "text/html"))
  56.     url-current-mime-type "text/html")
  57.   (set-buffer (get-buffer-create url-working-buffer))
  58.   (let* ((urlobj (if (vectorp url) url
  59.            (url-generic-parse-url url)))
  60.      (host (or (url-host urlobj) "localhost"))
  61.      (port (or (url-port urlobj)
  62.            (cdr-safe (assoc "finger" url-default-ports))))
  63.      (user (url-unhex-string (url-filename urlobj)))
  64.      (proc (url-open-stream "finger" url-working-buffer host
  65.                 (string-to-int port))))
  66.     (if (not (processp proc))
  67.     nil
  68.       (process-kill-without-query proc)
  69.       (set-process-sentinel proc 'ignore)
  70.       (if (= (string-to-char user) ?/)
  71.       (setq user (substring user 1 nil)))
  72.       (goto-char (point-min))
  73.       (insert "<html>\n"
  74.           " <head>\n"
  75.           "  <title>Finger information for " user "@" host "</title>\n"
  76.           " </head>\n"
  77.           " <body>\n"
  78.           "  <h1>Finger information for " user "@" host "</h1>\n"
  79.           "  <hr>\n"
  80.           "  <pre>\n")
  81.       (process-send-string proc (concat user "\r\n"))
  82.       (while (memq (url-process-status proc) '(run open))
  83.     (url-after-change-function)
  84.     (url-accept-process-output proc))
  85.       (goto-char (point-min))
  86.       (url-replace-regexp "^Process .* exited .*code .*$" "")
  87.       (goto-char (point-max))
  88.       (insert "  </pre>\n"
  89.           " </body>\n"
  90.           "</html>\n"))))
  91.  
  92. (defun url-do-terminal-emulator (type server port user)
  93.   (terminal-emulator
  94.    (generate-new-buffer (format "%s%s" (if user (concat user "@") "") server))
  95.    (case type
  96.      (rlogin "rlogin")
  97.      (telnet "telnet")
  98.      (tn3270 "tn3270")
  99.      (otherwise
  100.       (error "Unknown terminal emulator required: %s" type)))
  101.    (case type
  102.      (rlogin
  103.       (if user
  104.       (list server "-l" user)
  105.     (list server)))
  106.      (telnet
  107.       (if user (message "Please log in as user: %s" user))
  108.       (if port
  109.       (list server port)
  110.     (list server)))
  111.      (tn3270
  112.       (if user (message "Please log in as user: %s" user))
  113.       (list server)))))
  114.  
  115. (defun url-generic-emulator-loader (url)
  116.   (if (get-buffer url-working-buffer)
  117.       (kill-buffer url-working-buffer))
  118.   (or (string-match "^\\([^:]+\\):/*\\(.*@\\)*\\([^/]*\\)/*" url)
  119.       (error "Invalid URL: %s" url))
  120.   (let* ((type (intern (downcase (match-string 1 url))))
  121.      (server (match-string 3 url))
  122.      (name (if (match-beginning 2)
  123.            (substring url (match-beginning 2) (1- (match-end 2)))))
  124.      (port (if (string-match ":" server)
  125.            (prog1
  126.                (substring server (match-end 0))
  127.              (setq server (substring server 0 (match-beginning 0)))))))
  128.     (url-do-terminal-emulator type server port name)))
  129.  
  130. (fset 'url-rlogin 'url-generic-emulator-loader)
  131. (fset 'url-telnet 'url-generic-emulator-loader)
  132. (fset 'url-tn3270 'url-generic-emulator-loader)
  133.  
  134. (defun url-proxy (url)
  135.   ;; Retrieve URL from a proxy.
  136.   ;; Expects `url-using-proxy' to be bound to the specific proxy to use."
  137.   (let ((urlobj (url-generic-parse-url url)))
  138.     (url-set-target urlobj nil)
  139.     (url-http url-using-proxy (url-recreate-url urlobj))))
  140.  
  141. (defvar url-webmail-gateway "w3mail@gmd.de"
  142.   "*Where to send webmail requests")
  143.  
  144. (defvar url-webmail-switches '(" " "-uu -z" "-uu -z -s 100"))
  145.  
  146. (defun url-proxy-via-mail (url)
  147.   ;; Return URL from a web->mail gateway
  148.   (let ((urlobj (url-generic-parse-url url)))
  149.     (funcall url-mail-command)
  150.     (set (make-local-variable 'inhibit-read-only) t)
  151.     (goto-char (point-min))
  152.     (if (search-forward mail-header-separator nil t)
  153.     (progn
  154.       (forward-char 1)
  155.       (delete-region (point) (point-max)))
  156.       (goto-char (point-max)))
  157.     (if (fboundp 'widget-minor-mode)
  158.     (widget-minor-mode 1))
  159.     (apply 'widget-create 'menu-choice
  160.        :value " "
  161.        :format "%[%t%] %v"
  162.        :tag "get"
  163.        (mapcar (lambda (x) (list 'choice-item :format "%v" x))
  164.            url-webmail-switches))
  165.     (insert " " url)
  166.     (if url-request-data
  167.     (insert "?" url-request-data))
  168.     (url-mail-goto-field "To")
  169.     (insert url-webmail-gateway)))
  170.  
  171. ;; ftp://ietf.org/internet-drafts/draft-masinter-url-data-02.txt
  172. (defun url-data (url)
  173.   (set-buffer (get-buffer-create url-working-buffer))
  174.   (let ((content-type nil)
  175.     (encoding nil)
  176.     (data nil))
  177.     (cond
  178.      ((string-match "^data:\\([^;,]*\\);*\\([^,]*\\)," url)
  179.       (setq content-type (match-string 1 url)
  180.         encoding (match-string 2 url)
  181.         data (url-unhex-string (substring url (match-end 0))))
  182.       (if (= 0 (length content-type)) (setq content-type "text/plain"))
  183.       (if (= 0 (length encoding)) (setq encoding "8bit")))
  184.      (t nil))
  185.     (setq url-current-content-length (length data)
  186.       url-current-mime-type content-type
  187.       url-current-mime-encoding encoding
  188.       url-current-mime-headers (list (cons "content-type" content-type)
  189.                      (cons "content-encoding" encoding)))
  190.     (and data (insert data))))
  191.  
  192. (provide 'url-misc)
  193.